home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / N-P / PopUpMenu Demo ƒ / PopUpMenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-17  |  16.1 KB  |  654 lines  |  [TEXT/KAHL]

  1. /*
  2. ** Program:        PopUpMenu Demo for System 7.0
  3. ** File:        PopUpMenu.c
  4. ** Written By:    Joe Zobkiw
  5. ** Date:        Saturday, June 1, 1991 • 11:32:11 AM
  6. **
  7. ** Copyright © 1991 Joe Zobkiw
  8. ** All rights reserved.
  9. **
  10. ** AFL Zobkiw @ America Online
  11. */
  12.  
  13. /* ----------------------------------------------
  14.     This is a short example (and a very simple one as well) of how to use the
  15.     standard Sytem 7.0 Pop-Up Menu control. This is not the only way to use the
  16.     control, it can be done any number of ways. 
  17.     
  18.     I for instance, choose to implement a statText item to be the "title" of my 
  19.     control. You can also give the control a title of it’s own and have it draw 
  20.     it for you automatically.
  21.     
  22.     Some other cool things are:
  23.     
  24.         • DrawGrayFrameMinusText() routine which handles drawing the “sample”
  25.         area outline in the dialog.
  26.         • ZoomRect() which allows you to draw “Finder like” zoom rectangles.
  27.         • DialogFilter() which shows you a simple way to handle a dialog filter.
  28.     
  29.     Take this code for what it is worth…just a quick hack to learn how to do it
  30.     simply and easily. Have fun and feel free to use this code if you like. This
  31.     code is hereby in the pubic domain. (It said public, I changed it ;)
  32.     
  33.     There are not many comments since this stuff is pretty darned easy!
  34.    ---------------------------------------------- */
  35.  
  36. #include "PopUpMenu.h"
  37. #include <string.h>
  38. #include <Sound.h>
  39.  
  40.  
  41. /* --- global variables ------------------------- */
  42.  
  43. DialogPtr        gDialog        = nil;
  44. ControlHandle    gFontPopUp    = nil;
  45. ControlHandle    gAlignPopUp    = nil;
  46. ControlHandle    gSizePopUp    = nil;
  47. Rect            gFontLabelRect;
  48. Rect            gAlignLabelRect;
  49. Rect            gSizeLabelRect;
  50. Rect            gSampleRect;
  51. StringHandle    gSampleStr    = nil;
  52. short            gAlign        = ALIGN_LEFT_ITEM;
  53. short            gFontNum    = 0;
  54. short            gSize        = 9;
  55. short            gBrothersHead = 0;
  56.  
  57. #define SysFontFamPtr ((short *) 0x0BA6)
  58. #define SysFontSizePtr ((short *) 0x0BA8)
  59. #define CurFMInputPtr ((long *) 0x0988)
  60. #define LastSpExtraPtr ((long *) 0x0B4C)
  61.  
  62. static void ChangeSystemFont(short fontNum, short fontSize)
  63. {
  64.  if ((*SysFontFamPtr != fontNum) || (*SysFontSizePtr != fontSize)) {
  65.   *SysFontFamPtr = fontNum;
  66.   *SysFontSizePtr = fontSize;
  67.   *CurFMInputPtr = -1L;
  68.   *LastSpExtraPtr = -1L;  /* tells Font Manager to flush & reload font cache */
  69.  } /* otherwise, *SysFontFamPtr == fontNum && *SysFontSizePtr == fontSize, do
  70. nothing */
  71. } /* ChangeSystemFont */
  72.  
  73.  
  74. /* ----------------------------------------------
  75.     This is our main() program.
  76.    ---------------------------------------------- */
  77. main() {
  78.     InitToolBox();
  79.     CheckEnvironment();
  80.     
  81.     CreateObjects();
  82.     
  83.     ZoomFromCorner(gDialog);
  84.  
  85.     DoDialog();
  86.     
  87.     ExitApplication(FALSE);
  88. }
  89.  
  90. /* ----------------------------------------------
  91.     Center a rectangle in the screen…not the exact
  92.     algorithm that System 7 uses…
  93.     but good enough for our zoomrect routine.
  94.    ---------------------------------------------- */
  95. #define        Max(x, y)        ((x) > (y) ? (x) : (y))
  96.  
  97. Rect CenterRect(Rect    r)
  98. {
  99.     short    left, top;
  100.     
  101.     left = (screenBits.bounds.right - (r.right - r.left)) / 2;
  102.     top = (screenBits.bounds.bottom - (r.bottom - r.top)) / 3;
  103.     top = Max(top, GetMBarHeight() + 1);
  104.  
  105.     r.right += left - r.left;
  106.     r.left = left;
  107.     r.bottom += top - r.top;
  108.     r.top = top;
  109.     
  110.     /* this is needed to appease the rects to look better under system 7.0 */
  111.     r.top += 35;
  112.     r.bottom += 90;
  113.     
  114.     return(r);
  115. }
  116.     
  117. /* ----------------------------------------------
  118.     Zoom our dialog window from the corner of the 
  119.     screen…ala Welch.
  120.    ---------------------------------------------- */
  121. void ZoomFromCorner(DialogPtr dialog)
  122. {
  123.     Rect    smallRect = {0,0,1,1};
  124.     Rect    middleRect;    
  125.     Rect    dialogRect;
  126.     
  127.     dialogRect = dialog->portRect;
  128.     dialogRect = CenterRect(dialogRect);
  129.     middleRect = dialogRect;
  130.     InsetRect(&middleRect,100,100);
  131.  
  132.     DrawMenuBar();    /* this is the secret ingredient */
  133.  
  134.     ZoomRect(&smallRect, &middleRect, TRUE, TRUE);
  135.     ZoomRect(&middleRect, &dialogRect, TRUE, TRUE);
  136. }
  137.  
  138. /* ----------------------------------------------
  139.     Zoom our dialog window from the corner of the 
  140.     screen…ala Welch.
  141.    ---------------------------------------------- */
  142. void ZoomToCorner(DialogPtr dialog)
  143. {
  144.     Rect    smallRect = {0,0,1,1};
  145.     Rect    middleRect;    
  146.     Rect    dialogRect;
  147.     
  148.     dialogRect = dialog->portRect;
  149.     dialogRect = CenterRect(dialogRect);
  150.     middleRect = dialogRect;
  151.     InsetRect(&middleRect,100,100);
  152.  
  153.     DrawMenuBar();    /* this is the secret ingredient */
  154.     
  155.     ZoomRect(&middleRect, &dialogRect, FALSE, TRUE);
  156.     ZoomRect(&smallRect, &middleRect, FALSE, TRUE);
  157. }
  158.  
  159. /* ----------------------------------------------
  160.     Handle our dialog here…this is the meat of the 
  161.     program.
  162.    ---------------------------------------------- */
  163. void DoDialog(void)
  164. {
  165.     GrafPtr                savePort;
  166.     Boolean                dialogDone = FALSE;
  167.     short                itemHit, part, item, fontNum;
  168.     Point                pt;
  169.     Rect                r, r2;
  170.     MenuHandle            menuHandle = nil;
  171.     popupPrivateDataHdl    privateData = nil;
  172.     Str255                fontName, sizeStr;
  173.     long                sizeLong;
  174.     
  175.     GetPort(&savePort);
  176.     SetPort(gDialog);
  177.  
  178.     ShowWindow(gDialog);
  179.  
  180.     /* draw initial font properly */
  181.     item = GetCtlValue(gFontPopUp);
  182.     privateData = (MenuHandle)(*gFontPopUp)->contrlData;
  183.     menuHandle = (popupPrivateDataHdl)(*privateData)->mHandle;
  184.     GetItem(menuHandle, item, &fontName);
  185.     GetFNum(fontName, &fontNum);
  186.     if (fontNum != gFontNum) {
  187.         gFontNum = fontNum;                    
  188.         DrawSampleString();
  189.     }
  190.  
  191.     while (!dialogDone) {
  192.         ModalDialog((ProcPtr)&DialogFilter,&itemHit);
  193.         switch(itemHit)
  194.         {
  195.             case QUIT_ITEM:
  196.                 HideWindow(gDialog);
  197.                 dialogDone = TRUE;
  198.                 ZoomToCorner(gDialog);
  199.                 break;
  200.             
  201.             case ICON_ITEM: {
  202.                 long    lMnuAndItm;
  203.                 Point    pt;
  204.                                 
  205.                 GetMouse(&pt);
  206.                 LocalToGlobal(&pt);
  207.                 privateData = (MenuHandle)(*gSizePopUp)->contrlData;
  208.                 menuHandle = (popupPrivateDataHdl)(*privateData)->mHandle;
  209.                                 
  210.                  /* save old values of low-memory globals: */
  211.                 {
  212.                  short    saveSysFontFam = *SysFontFamPtr;
  213.                  short    saveSysFontSize = *SysFontSizePtr;
  214.                 
  215.                  /* set the font information from instance variables: */
  216.                  ChangeSystemFont(geneva, 9);
  217.  
  218.                 lMnuAndItm = PopUpMenuSelect(menuHandle, pt.v, pt.h, 0);
  219.                 
  220.                  /* set the font information back to saved variables: */
  221.                  ChangeSystemFont(saveSysFontFam, saveSysFontSize);
  222.                 }
  223.                 
  224.                 break;
  225.                 }
  226.                 
  227.                 
  228.                 /****************
  229.                 PlaySound(AHEM_SND_ID);
  230.                 gBrothersHead++;
  231.                 if (gBrothersHead == 9) {
  232.                     Alert(BROTHERS_HEAD_ALRT_ID,nil);
  233.                     gBrothersHead = 0;
  234.                 }
  235.                 break;
  236.                 ******************/
  237.                 
  238.             case FONT_USER_ITEM:
  239.                 GetMouse(&pt);
  240.                 r = GetDItemRect(gDialog,FONT_LABEL_ITEM);
  241.                 InvertRect(&r);
  242.                 part = TrackControl(gFontPopUp,pt,(Ptr)-1);
  243.                 InvertRect(&r);
  244.                 
  245.                 item = GetCtlValue(gFontPopUp);
  246.                 privateData = (MenuHandle)(*gFontPopUp)->contrlData;
  247.                 menuHandle = (popupPrivateDataHdl)(*privateData)->mHandle;
  248.                 
  249.                 GetItem(menuHandle, item, &fontName);
  250.                 GetFNum(fontName, &fontNum);
  251.                 
  252.                 if (fontNum != gFontNum) {
  253.                     gFontNum = fontNum;                    
  254.                     ZoomRect(&r,&gSampleRect,TRUE,FALSE);
  255.                     DrawSampleString();
  256.                 }
  257.                                 
  258.                 break;
  259.                 
  260.             case ALIGN_USER_ITEM:
  261.                 GetMouse(&pt);
  262.                 r = GetDItemRect(gDialog,ALIGN_LABEL_ITEM);
  263.                 InvertRect(&r);
  264.                 part = TrackControl(gAlignPopUp,pt,(Ptr)-1);
  265.                 InvertRect(&r);
  266.                 
  267.                 item = GetCtlValue(gAlignPopUp);
  268.                 if (item != gAlign) {
  269.                     gAlign = item;
  270.                     ZoomRect(&r,&gSampleRect,TRUE,FALSE);
  271.                     DrawSampleString();
  272.                 }
  273.                 
  274.                 break;
  275.  
  276.             case SIZE_USER_ITEM:
  277.                 GetMouse(&pt);
  278.                 r = GetDItemRect(gDialog,SIZE_LABEL_ITEM);
  279.                 InvertRect(&r);
  280.                 part = TrackControl(gSizePopUp,pt,(Ptr)-1);
  281.                 InvertRect(&r);
  282.                 
  283.                 item = GetCtlValue(gSizePopUp);
  284.                 privateData = (MenuHandle)(*gSizePopUp)->contrlData;
  285.                 menuHandle = (popupPrivateDataHdl)(*privateData)->mHandle;
  286.                 
  287.                 GetItem(menuHandle, item, &sizeStr);
  288.                 StringToNum(sizeStr,&sizeLong);
  289.                 
  290.                 if (sizeLong != (long)gSize) {
  291.                     gSize = sizeLong;
  292.                     ZoomRect(&r,&gSampleRect,TRUE,FALSE);
  293.                     DrawSampleString();
  294.                 }
  295.                 break;
  296.                 
  297.             default:
  298.                 break;
  299.         }
  300.     }
  301.     
  302.     SetPort(savePort);
  303. }
  304.  
  305. /* ----------------------------------------------
  306.     Handle special dialog thangs.
  307.    ---------------------------------------------- */
  308. pascal Boolean    DialogFilter(DialogPtr d, EventRecord *e, short *item)
  309. {
  310.     short    type;
  311.     Handle    h;
  312.     Rect    r;
  313.     short    chr, mod, itemNum;
  314.     long    tick;
  315.  
  316.     if (e->what == updateEvt) {
  317.         if (d == (DialogPtr)e->message) DrawSampleString();
  318.         return(false);
  319.     }
  320.  
  321.     if (e->what != keyDown) return(false);
  322.  
  323.     itemNum = 0;
  324.  
  325.     chr = e->message   & charCodeMask;
  326.     mod = e->modifiers & keyCodeMask;
  327.  
  328.     if ((chr == 0x0D) || (chr == 0x03)) {        /* If return or enter... */
  329.         if (!(mod & (cmdKey + optionKey + controlKey))) itemNum = 1;
  330.     }
  331.  
  332.     if (itemNum) {
  333.         GetDItem(d, itemNum, &type, &h, &r);
  334.         HiliteControl((ControlHandle)h, 1);
  335.         tick = TickCount();
  336.         while (TickCount() < tick + 8);
  337.         HiliteControl((ControlHandle)h, 0);
  338.         *item = itemNum;
  339.         return(true);
  340.     }
  341.  
  342.     return(false);
  343. }
  344.  
  345. /* ----------------------------------------------
  346.     Create our dialog and our controls for the standard
  347.     System 7.0 Pop-Up Menus.
  348.     
  349.     We also take a few moments to initialize some other
  350.     variables here as well.
  351.    ---------------------------------------------- */
  352. void CreateObjects(void)
  353. {
  354.     Rect    r;
  355.     
  356.     gDialog = GetNewDialog(DIALOG_ID,nil,(WindowPtr)-1L);
  357.     if (!gDialog) ExitApplication(TRUE);
  358.     
  359.     r = GetDItemRect(gDialog, FONT_USER_ITEM);
  360.     gFontPopUp = NewControl(gDialog,
  361.                             &r,
  362.                             (char*)'\p',
  363.                             TRUE,
  364.                             popupTitleLeftJust + popupTitleNoStyle,
  365.                             FONT_MENU_ID,
  366.                             0,    /* width of title? */
  367.                             popupMenuCDEFProc + popupUseAddResMenu + popupFixedWidth,
  368.                             'FONT');
  369.                             
  370.     if (!gFontPopUp) ExitApplication(TRUE);
  371.     
  372.     r = GetDItemRect(gDialog, ALIGN_USER_ITEM);
  373.     gAlignPopUp = NewControl(gDialog,
  374.                             &r,
  375.                             (char*)'\p',
  376.                             TRUE,
  377.                             popupTitleLeftJust + popupTitleNoStyle,
  378.                             ALIGN_MENU_ID,
  379.                             0,    /* width of title? */
  380.                             popupMenuCDEFProc + popupFixedWidth,
  381.                             (long)nil);
  382.     
  383.     if (!gAlignPopUp) ExitApplication(TRUE);
  384.     
  385.     r = GetDItemRect(gDialog, SIZE_USER_ITEM);
  386.     gSizePopUp = NewControl(gDialog,
  387.                             &r,
  388.                             (char*)'\p',
  389.                             TRUE,
  390.                             popupTitleLeftJust + popupTitleNoStyle,
  391.                             SIZE_MENU_ID,
  392.                             0,    /* width of title? */
  393.                             popupMenuCDEFProc + popupFixedWidth,
  394.                             (long)nil);
  395.     
  396.     if (!gSizePopUp) ExitApplication(TRUE);
  397.  
  398.     gFontLabelRect = GetDItemRect(gDialog, FONT_LABEL_ITEM);
  399.     gAlignLabelRect = GetDItemRect(gDialog, ALIGN_LABEL_ITEM);
  400.     gSizeLabelRect = GetDItemRect(gDialog, SIZE_LABEL_ITEM);
  401.     gSampleRect = GetDItemRect(gDialog, SAMPLE_USER_ITEM);
  402.     
  403.     SetDItemProc(gDialog, SAMPLE_USER_ITEM, (ProcPtr)&DrawGrayFrameMinusText);
  404.     SetDItemProc(gDialog, MENU_OUTLINE_USER_ITEM, (ProcPtr)&DrawGrayFrame);
  405.     
  406.     gSampleStr = GetString(SAMPLE_TEXT_STR);
  407.     if (!gSampleStr) ExitApplication(TRUE);
  408. }
  409.  
  410. /* ----------------------------------------------
  411.     draw some text
  412.    ---------------------------------------------- */
  413. void DrawSampleString()
  414. {
  415.     Rect    r;
  416.     short    just;
  417.         
  418.     TextFont(gFontNum);                /* set the font */
  419.     TextSize(gSize);                /* and the size */
  420.     
  421.     switch (gAlign) {                /* figure out how we are to align our text */
  422.         case ALIGN_LEFT_ITEM:
  423.             just = teJustLeft;
  424.             break;
  425.         case ALIGN_CENTER_ITEM:
  426.             just = teJustCenter;
  427.             break;
  428.         case ALIGN_RIGHT_ITEM:
  429.             just = teJustRight;
  430.             break;
  431.     }
  432.  
  433.     r = gSampleRect;                /* copy the useritem rect since we have to change it */
  434.     InsetRect(&r,7,7);                /* inset it */
  435.     EraseRect(&r);                    /* erase the area */
  436.     
  437.     HLock((Handle)gSampleStr);
  438.     TextBox(*gSampleStr + sizeof(Byte), *gSampleStr[0] ,&r, just);    /* draw the text! */
  439.     HUnlock((Handle)gSampleStr);
  440.  
  441.     TextFont(systemFont);            /* restore the font */
  442.     TextSize(12);
  443. }
  444.  
  445. /* ----------------------------------------------
  446.     draw a gray framed item.
  447.    ---------------------------------------------- */
  448. pascal void DrawGrayFrame( register DialogPtr d,
  449.                            register short item)
  450. {
  451.     Rect r;
  452.  
  453.     r = GetDItemRect(d, item);
  454.     PenNormal();
  455.     PenPat(gray);
  456.     FrameRect(&r);
  457.     PenNormal();
  458. }
  459.  
  460. /* ----------------------------------------------
  461.     draw a gray framed item making ammends for a
  462.     static text item which is one item less that
  463.     the useritem to be framed.
  464.    ---------------------------------------------- */
  465. pascal void DrawGrayFrameMinusText( register DialogPtr d,
  466.                            register short item)
  467. {
  468.     Rect r, rT;
  469.  
  470.     rT = GetDItemRect(d, item-1);    /* Text */
  471.     r = GetDItemRect(d, item);        /* User item */
  472.     PenNormal();
  473.     PenPat(gray);
  474.     MoveTo(rT.right + 2, r.top);
  475.     LineTo(r.right, r.top);
  476.     LineTo(r.right, r.bottom);
  477.     LineTo(r.left, r.bottom);
  478.     LineTo(r.left, r.top);
  479.     LineTo(rT.left - 3, r.top);
  480.     PenNormal();
  481. }
  482.  
  483. /* ----------------------------------------------
  484.     Return the rectangle of a dialog item
  485.    ---------------------------------------------- */
  486. Rect GetDItemRect(DialogPtr d, short item)
  487. {
  488.     short     kind;
  489.     Handle     h;
  490.     Rect     r;
  491.  
  492.     GetDItem (d, item, &kind, &h, &r);
  493.     return (r);
  494. }
  495.  
  496. /* ----------------------------------------------
  497.     Set the update proc of a user item
  498.    ---------------------------------------------- */
  499. void SetDItemProc(DialogPtr d, short item, ProcPtr proc)
  500. {
  501.     short     type;
  502.     Handle     h;
  503.     Rect     r;
  504.  
  505.     GetDItem (d, item, &type, &h, &r);
  506.     SetDItem(d, item, type, proc, &r);
  507. }
  508.  
  509.  
  510. /* ----------------------------------------------
  511.     Make sure we can run in this environment. Gestalt
  512.     checks may also be nice to have here but until THINK
  513.     C 5.0 comes out, forget it!
  514.    ---------------------------------------------- */
  515. void CheckEnvironment(void)
  516. {
  517.     SysEnvRec    e;
  518.     OSErr        err;
  519.     
  520.     if (!(err = SysEnvirons (curSysEnvVers, &e))) {
  521.         if (e.systemVersion < 0x0700)
  522.             ExitApplication(TRUE);
  523.     } else {
  524.         ExitApplication(TRUE);
  525.     }
  526. }
  527.  
  528. /* ----------------------------------------------
  529.     play an ‘snd ’ resource
  530.    ---------------------------------------------- */
  531. void PlaySound(short    id)
  532. {
  533.     Handle    h;
  534.     OSErr    err;
  535.     
  536.     h = GetResource('snd ', id);        
  537.     if (h != nil) {
  538.         LoadResource(h);                                
  539.         HNoPurge(h);                                            
  540.         err = SndPlay(nil, h, FALSE);                                        
  541.         HPurge(h);                                                            
  542.         ReleaseResource(h);
  543.     }                                
  544. }
  545.  
  546. /* ----------------------------------------------
  547.     utility routine used by ZoomRect()
  548.    ---------------------------------------------- */
  549. short Blend(register Fixed fract, 
  550.             short smallCoord, 
  551.             short bigCoord)
  552. {
  553.      return (FixRound(FixMul(fract, (long) bigCoord << 16) +  
  554.      FixMul(0x00010000 - fract, (long) smallCoord << 16)));
  555. }
  556.  
  557. /* ----------------------------------------------
  558.     draw some zoooooooom rects!
  559.    ---------------------------------------------- */
  560. #define        ZOOM_STEPS        16
  561. #define     DELAY_TICKS        1
  562.  
  563. void ZoomRect(register Rect *smallRect, 
  564.               register Rect *bigRect, 
  565.               Boolean zoomUp, 
  566.               Boolean useWMgrPort)
  567. {
  568.     register Fixed    fract, factor;
  569.     GrafPtr            savePort;
  570.     GrafPtr            wMgrPort;
  571.     PenState        savePenState;
  572.     Rect              r1, r2, r3, r4;
  573.      register short    i, j;
  574.     long            ticks;
  575.     
  576.     if (useWMgrPort) {
  577.         GetPort(&savePort);
  578.         GetWMgrPort(&wMgrPort);
  579.         SetPort(wMgrPort);
  580.     }
  581.     
  582.     GetPenState(&savePenState);
  583.     PenPat(gray);
  584.     PenMode(notPatXor);
  585.     
  586.     if (zoomUp) {
  587.         r1 = *smallRect;
  588.         factor = FixRatio(6, 5);
  589.         fract = FixRatio(541, 10000);        /* 5/6 ^ 16 */
  590.     }    else {
  591.         r1 = *bigRect;
  592.         factor = FixRatio(5, 6);
  593.         fract = 0x00010000;
  594.     }
  595.     
  596.     r3 = r2 = r1;
  597.     FrameRect(&r1);
  598.     
  599.     for (i = 0; i < ZOOM_STEPS; ++i) {
  600.         r4.top = Blend(fract, smallRect->top, bigRect->top);
  601.         r4.left = Blend(fract, smallRect->left, bigRect->left);
  602.         r4.bottom = Blend(fract, smallRect->bottom, bigRect->bottom);
  603.         r4.right = Blend(fract, smallRect->right, bigRect->right);
  604.         FrameRect(&r4);
  605.         FrameRect(&r1);
  606.         r1 = r2;
  607.         r2 = r3;
  608.         r3 = r4;
  609.         
  610.         fract = FixMul(fract, factor);
  611.         
  612.         Delay(DELAY_TICKS,&ticks);
  613.     }
  614.     
  615.     FrameRect(&r1);
  616.     FrameRect(&r2);
  617.     FrameRect(&r3);
  618.     if (useWMgrPort) {
  619.         SetPort(savePort);
  620.     }
  621.     SetPenState(&savePenState);    
  622. }
  623.  
  624. /* ----------------------------------------------
  625.     Beep and exit!
  626.    ---------------------------------------------- */
  627. void ExitApplication(Boolean error)
  628. {
  629.     if (gFontPopUp) DisposeControl(gFontPopUp);        /* clean up handles */
  630.     if (gAlignPopUp) DisposeControl(gAlignPopUp);
  631.     if (gSizePopUp) DisposeControl(gSizePopUp);
  632.     if (gDialog) DisposDialog(gDialog);
  633.     if (gSampleStr) ReleaseResource(gSampleStr);
  634.     
  635.     if (error) 
  636.         Alert(GENERIC_ALRT_ID,nil);
  637.     
  638.     ExitToShell();
  639. }
  640.  
  641. /* ----------------------------------------------
  642.     Initialize the Toolbox
  643.    ---------------------------------------------- */
  644. void InitToolBox(void)
  645. {
  646.     
  647.     InitGraf(&thePort);
  648.     InitFonts();
  649.     InitWindows();
  650.     InitMenus();
  651.     TEInit();
  652.     InitDialogs(nil);
  653.     InitCursor();
  654. }